package cn.edu.scau.cmi.chenmiaopeng.hibernate.domain;
import cn.edu.scau.cmi.chenmiaopeng.hibernate.domain.Student;
import cn.edu.scau.cmi.chenmiaopeng.hibernate.domain.Teacher;

public class Student implements Cloneable{
  private long id;
  private String name;
  private Teacher tutor;
	/** default constructor */
	public Student() {
	}
	public Student(long id) {
		this.id = id;
	}
  public Student(long id,String name) {
	  this.id = id;
	  this.name = name;
  }
  public void setId(long id) {  //驼峰命名法
	  this.id = id;
  }
  public void setName(String name) {
	  this.name = name;
  }
  public void setTeacher(Teacher tutor) {
	  this.tutor = tutor;
  }
  public long getId() {
	  return id;
  }
  public String getName() {
	  return name;
  }
  public Teacher getTeacher() {  //不能用getTutor，只能用getTeacher() hibernate框架的规定
	  return tutor;
  }
  public int compareTo(Student other) {  //按id升序排
	  if(id>other.getId()) return 1;
	  else return -1;
  }
  public String toString() {
	  return "学生学号:"+id+" 学生名:"+name;
  }
  public Object clone(){
	  Student stu = null;
	  try {
	   stu = (Student)super.clone();
	  }catch (CloneNotSupportedException e){
	  e.printStackTrace();
	  }
	  return stu;
	  }
  public int hashCode() {  //必须返回一样，equals()才能判断  会影响update()
	  return 1;
  }
  public boolean equals(Object obj) {
	  if(obj==null) return false;
	  else if(!(obj instanceof Student)) return false;
	  else {
		  Student otherStu = (Student)obj;
		  if(this.getId()==otherStu.getId()&&this.getName().equals(otherStu.getName())) return true;
		  else return false;
	  }
  }
}
